package com.kimstore.bean;

import com.kimstore.utilities.Encryption;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "user")
public class User {

    public static final int TYPE_ADMIN = 0;
    public static final int TYPE_ADMIN_B = 1;
    public static final int TYPE_STOCKS = 2;
    public static final int TYPE_SALES = 3;
    public static final int TYPE_TECHNICAL = 4;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String username;
    private String password;
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_login")
    private Date lastLogin;
    private int type;

    public User() {
    }

    public static int getTypeNumber(String type) {
        switch (type) {
            case "Admin":
                return 0;
            case "Admin B":
                return 1;
            case "Stocks":
                return 2;
            case "Sales":
                return 3;
            case "Technical":
                return 4;
            default:
                return 5;
        }
    }

    public static String getTypeString(int type) {
        switch (type) {
            case 0:
                return "Admin";
            case 1:
                return "Admin B";
            case 2:
                return "Stocks";
            case 3:
                return "Sales";
            case 4:
                return "Technical";
            default:
                return "Unknown";
        }
    }

    public User(String username, String password, int type) {
        this.username = username;
        this.password = Encryption.sha(password);
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
